/**
 * Chengzai.com Inc.
 * Copyright (c) 2016-2018 All Rights Reserved.
 */
package com.auxgroup.hr.front.service.hireperson.impl;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.dao.domain.PsCHireChiguT;
import com.auxgroup.hr.front.dao.domain.PsCHirePrimaryClass;
import com.auxgroup.hr.front.dao.repository.PsCHireChiguTRepository;
import com.auxgroup.hr.front.service.hireperson.HireChiguTService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 持股协议服务
 *
 * @author tongqian.ni
 * @version $Id: HireChiguTServiceImpl, v 0.1  2019-01-04.
 */
@Service("hireChiguTServiceImpl")
public class HireChiguTServiceImpl implements HireChiguTService {
    private static final Logger logger = LoggerFactory.getLogger(HireChiguTServiceImpl.class);

    @Autowired
    private PsCHireChiguTRepository psCHireChiguTRepository;
    @Override
    public PsCHireChiguT getByHire(PsCHirePrimaryClass hirePrimary) {
        return psCHireChiguTRepository.findOne(hirePrimary);
    }

    @Override
    public PsCHireChiguT save(PsCHireChiguT outf) {
        Set<String> ignoreFields = new HashSet<>(Arrays.asList("cSeqno"));
        ObjectFieldUtils.handleNullValue(outf, ignoreFields);
        return psCHireChiguTRepository.save(outf);
    }
    @Override
    public Boolean delete(PsCHirePrimaryClass hirePrimary) {
        try {
            psCHireChiguTRepository.delete(hirePrimary);
        } catch (Exception e) {
            logger.error("delete PsCHireChiguT error: hirePrimary={}",hirePrimary,e);
            return false;
        }
        return true;
    }


    @Override
    public List<PsCHireChiguT> getAll(String rsHireId) {
        PsCHireChiguT outf = new PsCHireChiguT();
        outf.setRsHireId(rsHireId);
        return psCHireChiguTRepository.findAll(Example.of(outf),new Sort(Sort.Direction.DESC,"cSeqno"));
    }

}
